Page({
  data: {
    query: {
      current: 1,
      pageSize: 3,
    },
    // 列表数据
    list: [],
    total: 0,
    isFinsh: false,
    isLoading: false,
    isError: false,
  },
  onShow() {
    this.initData()
  },
  // 获取我的报修列表
  async initData() {
    this.setData({ isLoading: true })
    try {
      const { total, rows } = await wx.http.get('/repair', this.data.query)
      // console.log(rows);
      this.setData({ list: [...this.data.list, ...rows], total })
      if (this.data.list.length < total) {
        this.setData({ 'query.current': this.data.query.current + 1 })
      } else {
        this.setData({ isFinsh: true })
      }
    } catch (err) {
      console.log(err);
      this.setData({ isError: true })
    } finally {
      this.setData({ isLoading: false })
    }
  },
  // 滚动加载
  onScrolltolower() {
    // console.log(666);
    if (this.data.isFinsh) return
    if (this.data.isLoading) return
    this.initData()
  },
  // 出错重新加载
  onRush() {
    this.initData()
  },
  // 下拉刷新
  onRefresh() {
    this.setData({ list: [], 'query.current': 1, isFinsh: false, isLoading: false, isError: false })
    this.initData()
    wx.utils.toast('刷新成功')
    this.setData({ isRefresh: false })
  },
  goDetail(ev) {
    wx.navigateTo({
      url: '/repair_pkg/pages/detail/index?id=' + ev.mark.id,
    })
  },
  addRepair() {
    wx.navigateTo({
      url: '/repair_pkg/pages/form/index',
    })
  },
})
